package com.woniuxy.springmvcannotation;

import com.woniuxy.springnvcannotation.bean.UserBean;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.CookieValue;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * @author linke
 * @version 1.0
 * @className: CookieController
 * @description: 接收Cookie信息(了解)使用@CookieValue 来获得，Cookie的内容*
 * @date 2021/11/13 18:11
 * @Controller 将控制器交给spring容器管理 表示要跳页面
 * @RequestMapping 定义页面请求路径，与执行该路径请求的 方法之间的映射关系
 */
@RequestMapping("/cookie")
@Controller
public class CookieController {
    /**
     *
     * @param model
     * @param userBean
     * @param sessionID 返回Cookie内容
     * @return 返回的字符串，就是需要跳转的页面
     */
    @RequestMapping(value = "/login")
    public String login(Model model, UserBean userBean, @CookieValue("JSESSIONID") String sessionID){
        System.out.println(userBean);//UserBean(id=null, userName=null, loginName=22, password=33, age=null)
        System.out.println(sessionID);//A2DBA03318D75B6A3DCCFF4CB59B9A91

        userBean.setUserName("张三");
        model.addAttribute("user",userBean);
        return "sysmag/main";
    }
}
